package com.lc.afbx.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.adapters.ExtractedAdapter;
import com.lc.afbx.conn.GetApiYiTiXian;
import com.lc.afbx.util.DateTimePickDialogUtil;
import com.lc.afbx.util.TimeUtil;
import com.lc.afbx.widget.MyListView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Created by Administrator on 2016/5/23.
 */
public class CommissionHasWithdrawalActivity extends BaseActivity implements View.OnClickListener {

    private TextView commission_had_endtime_tv;
    private TextView commission_had_starttime_tv;
    private String initDateTime;
    private String initEndTime;
//    private String hint;
//    private String endHint;
    private LinearLayout commission_had_title_ll;

    private MyListView commission_had_lv;
    private ExtractedAdapter adapter;
    private List<GetApiYiTiXian.Data> lists = new ArrayList<>();

    private GetApiYiTiXian getApiYiTiXian = new GetApiYiTiXian(new AsyCallBack<GetApiYiTiXian.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiYiTiXian.Info info) throws Exception {

            commission_had_title_ll.setVisibility(View.VISIBLE);

            lists.addAll(info.dataList);

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, TimeUtil.times(getApiYiTiXian.starttime) + "至" + TimeUtil.times(getApiYiTiXian.endtime) + "无提现记录");
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commision_had);

        Calendar calendar = Calendar.getInstance();
        //dialog显示当前时间
        initDateTime = calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONTH) - 3) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日";
        initEndTime = calendar.get(Calendar.YEAR) + "年" + calendar.get(Calendar.MONTH) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日";
        //txt显示默认时间
//        hint = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) - 2) + "-" + calendar.get(Calendar.DAY_OF_MONTH);
//        endHint = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);

        commission_had_lv = ((MyListView) findViewById(R.id.commission_had_lv));

        commission_had_endtime_tv = ((TextView) findViewById(R.id.commission_had_endtime_tv));
        commission_had_starttime_tv = ((TextView) findViewById(R.id.commission_had_starttime_tv));
        commission_had_title_ll = ((LinearLayout) findViewById(R.id.commission_had_title_ll));

        commission_had_lv.setFocusable(false);
        commission_had_lv.setAdapter(adapter = new ExtractedAdapter(context, lists));

    }


    @Override
    public void onClick(View view) {

        DateTimePickDialogUtil dialogUtil = null;

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.commission_had_starttime_rl:

                dialogUtil = new DateTimePickDialogUtil(this, initDateTime);
                dialogUtil.dateTimePicKDialog(commission_had_starttime_tv);

                return;

            case R.id.commission_had_endtime_rl:

                dialogUtil = new DateTimePickDialogUtil(this, initEndTime);
                dialogUtil.dateTimePicKDialog(commission_had_endtime_tv);

                return;

            case R.id.commission_had_bt:

                if (commission_had_starttime_tv.getText().toString().isEmpty() || commission_had_endtime_tv.getText().toString().isEmpty()) {

                    UtilToast.show(context, "请选择时间");
                    return;

                }

                String start = TimeUtil.dataOne(commission_had_starttime_tv.getText().toString());
                String end = TimeUtil.dataOne(commission_had_endtime_tv.getText().toString());

                if (Long.valueOf(end) - Long.valueOf(start) >= 0) {

                    lists.clear();

                    getApiYiTiXian.starttime = start;
                    getApiYiTiXian.endtime = end;
                    getApiYiTiXian.userid = BaseApplication.BasePreferences.readUserId();

                    getApiYiTiXian.execute(this);

                    return;

                } else {

                    UtilToast.show(context, "起始时间 大于 结束时间");

                    return;

                }


        }


    }

}
